package cn.heygod.graywhale.runtime.spring;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @className: SpringContextUtil
 * @author: Simon
 * @description: TODO
 * @date: 2023/11/27 23:05
 * @version: 1.0
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {

    private static ApplicationContext  CONTEXT;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        CONTEXT = applicationContext;
    }


    public static ApplicationContext get(){
        return CONTEXT;
    }

    public static Object bean(String beanName){
        return CONTEXT.getBean(beanName);
    }


    public static <T>T bean(String beanName, Class<T> type){
        return CONTEXT.getBean(beanName,type);
    }

    public static <T>T bean( Class<T> type){
        return CONTEXT.getBean(type);
    }


}
